﻿using B.S.Shop.Application.Command;
using B.S.Shop.Domain;
using B.S.Shop.ErrorCode;
using B.S.Shop.Infartructrue.Interfaces;
using MediatR;

namespace B.S.Shop.Application.Commandhandler
{
    public class ShopDelCommandHandler : IRequestHandler<ShopDelCommand, APIResult<int>>
    {
        public ShopDelCommandHandler(IBaseRepository<ShopClass> shopRepository)
        {
            ShopRepository = shopRepository;
        }

        public IBaseRepository<ShopClass> ShopRepository { get; }

        public async Task<APIResult<int>> Handle(ShopDelCommand request, CancellationToken cancellationToken)
        {
            var path = ShopRepository.GetAll().FirstOrDefault(a => a.ShopId == request.Id);
            path.IsDel = true;
            await ShopRepository.UpdateAsync(path);
            return new APIResult<int>
            {
                Code = ResultCode.success,
                Mag = "",
                data = 1
            };
        }
    }
}
